import { getToken, setToken, removeToken } from '@/utils/auth'
import { login } from '@/api/user'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    updateToken(state, token) {
      state.token = token
    },
    setToken(state, token) {
      state.token = token
      setToken(token)
    },
    removeToken(state, token) {
      state.token = ''
      removeToken()
    }
  },
  actions: {
    async  userLogin(context, loginForm) {
      console.log(context, 'context')
      const res = await login(loginForm)
      console.log('data---vuex', res.data)
      context.commit('updateToken', res.data)
    }
  }
}

